Making true copy of a list
Sometimes you need to make a copy of a list and you generally tend to to do it using the assignment ,
A = [1,2,3]
A = B
But it will not make be as duplicate list of a. Thus to make a true independent copy of a list we will use copy() method.
L.copy()
the same thing that you did by using list and copy functions can also be achieved as:
Listcopy= list[:]
Ques : Write a program to create a copy of a list.In the list's copy, add 10 to its first and last elements. Then display the lists ?
L1 = [17,24,15,30,34,27]
L2 = L1.copy()
print("Original List :",L1)
print("Created copy of the list :",L2)
L2[0] += 10
L2[-1] += 10
print("Copy of the list after changes :",L2)
print("Original List :",L1)